import React from 'react';
import {createStore, combineReducers, applyMiddleware, compose} from 'redux';
import { BrowserRouter, HashRouter, Route, Link, Switch } from 'react-router-dom';

import {Provider} from 'react-redux';
import reducers from './store/reducers.js';
import App from './App.js';
import {
  addTodo,
  toggleTodo,
  setVisibilityFilter,
  VisibilityFilters
} from './store/actions';
reducers.dispatch(addTodo('Learn about actions'))
reducers.dispatch(addTodo('Learn about reducers'))
reducers.dispatch(addTodo('Learn about reducers'))
reducers.dispatch(toggleTodo(0))
reducers.dispatch(toggleTodo(1))
reducers.dispatch(setVisibilityFilter(VisibilityFilters.SHOW_COMPLETED))
// 每次 state 更新时，打印日志
// 注意 subscribe() 返回一个函数用来注销监听器
const unsubscribe = reducers.subscribe(() =>
  console.log(reducers.getState())
)
console.log(reducers);
console.log(reducers.getState());
// 停止监听 state 更新
unsubscribe();
const Router = () => (
    <BrowserRouter>
        <Provider store ={reducers}>
            <App/>
        </Provider>
    </BrowserRouter>
)
export default Router;
